package com.lyshop.jinding.activitys;

import android.util.Log;
import android.view.View;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.lyshop.jinding.R;
import com.lyshop.jinding.adapters.CattleBillAdapter;
import com.lyshop.jinding.application.MyApplication;
import com.lyshop.jinding.base.BaseActivity;
import com.lyshop.jinding.base.BaseRVAdapter;
import com.lyshop.jinding.bean.SellOrderInfoBean;
import com.lyshop.jinding.net.ActionCallbackListener;
import com.lyshop.jinding.utils.RouteUtil;
import com.lyshop.jinding.utils.ToastUtil;


import java.util.ArrayList;
import java.util.List;

public class CattleBillActivity extends BaseActivity {

    private static final String TAG = "CattleBillActivity";
    private RecyclerView  rv_cattle_bill;
    private CattleBillAdapter adapter;
    private List list =new ArrayList();
    @Override
    protected int setContentView() {
        return R.layout.activity_cattle_bill;
    }

    @Override
    protected void findViews() {
        rv_cattle_bill = findViewById(R.id.rv_cattle_bill);
        rv_cattle_bill.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new CattleBillAdapter(mContext,list);
        rv_cattle_bill.setAdapter(adapter);
        adapter.setOnItemClickListener(new BaseRVAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(List data, View view, int position, long id) {
                SellOrderInfoBean bean = (SellOrderInfoBean)list.get(position);
                RouteUtil.toMarketActivity(CattleBillActivity.this, bean.pro_code);
            }
        });
        getListData();
    }
    @Override
    protected void setListeners() {

    }

    private void getListData(){
        mAppAction = MyApplication.getApplication().getAppAction();
        mAppAction.getOrderSquare(new ActionCallbackListener<List<SellOrderInfoBean>>() {
            @Override
            public void onSuccess(List<SellOrderInfoBean> data) {
                Log.e(TAG, "onSuccess: "+data.toString() );
                list.clear();
                list.addAll(data);
                adapter.notifyDataSetChanged();
            }

            @Override
            public void onFailure(String errorCode, String message) {
                ToastUtil.showToast(mContext,message);
            }
        });
    }
}
